#include <stdio.h>

void fastsort(int* a,int start,int end)
{
    if(start>=end)
    {
        return;
    }
    int left=start;
    int right=end;
    int temp=a[left];

    while(left<right)
    {
        while((left<right)&&(a[right]>temp))  
        {
            right--;
        }
        if(left<right)                   
        {
            a[left]=a[right];        
            left++;                    
        }
        while(left<right&&a[left]<temp)  
        {
            left++;
        }
        if(left<right)
        {
            a[right]=a[left];
            right--;
        }
    }
    a[left]=temp;

    fastsort(a,start,left-1);
    fastsort(a,right+1,end);
}


int arrayPairSum(int* nums, int numsSize) {
    int res=0;
    fastsort(nums,0,numsSize-1);
    for(int i=0;i<numsSize;i++)
    printf("%d ",nums[i]);
    printf("\n");
    for(int i=0;i<numsSize;i+=2)
    {
        res+=nums[i];
    }
    return res;
}

int main(int argc,char* argv[])
{
    int a[]={1,4,2,3};
    int len = sizeof(a)/4;
    int c = arrayPairSum(a,len);

    printf("%d\n",c);
    return 0;
}